<template>
    <div>
        <el-form label-width="85px" :model="form" label-position="right" ref="formRef" :rules="formRules">
            <el-form-item label="字典类别" prop="dictKind">
                <el-select v-model="form.dictKind">
                    <el-option v-for="item in kindOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="编号" prop="number">
                <el-input v-model="form.number"></el-input>
            </el-form-item>
            <el-form-item label="中文简体" prop="zhCn">
                <el-input v-model="form.zhCn"></el-input>
            </el-form-item>
            <el-form-item label="繁体">
                <el-input v-model="form.zhTw"></el-input>
            </el-form-item>
            <el-form-item label="英文">
                <el-input v-model="form.us"></el-input>
            </el-form-item>
            <el-form-item label="是否js翻译">
                <el-switch v-model="form.jsLang" size="large" inline-prompt :active-icon="Check" :inactive-icon="Close"
                    active-value="1" inactive-value="0" />
            </el-form-item>
            <el-form-item label="是否双语言">
                <el-switch v-model="form.doublelng" size="large" inline-prompt :active-icon="Check" :inactive-icon="Close"
                    active-value="1" inactive-value="0" />
            </el-form-item>
            <el-form-item label="备注">
                <el-input v-model="form.remark"></el-input>
            </el-form-item>

        </el-form>
        <div class="button-position">
            <el-button @click="updateVisible">取 消</el-button>
            <el-button type="primary" @click="updateLang(formRef)">确 定</el-button>
        </div>
    </div>
</template>

<script setup>
import { reactive, ref, onMounted } from 'vue';
import { FullScreen, CopyDocument, Check, Close } from '@element-plus/icons-vue'
import { ElNotification } from 'element-plus';
import Api from '@/api/model/system'
const emit = defineEmits(['updatetable'])
const props = defineProps({
    paramsData: {
        type: Object,
        defalut: {}
    }
})
onMounted(() => {
    getData()
    getInit()
})
// 查看用户数据的对象
const form = ref({})
const kindOptions = ref()
const formRef = ref()
const formRules = reactive({
    dicKind: [
        { required: true, message: "请输入类别", trigger: "blur" },
    ],
    number: [
        { required: true, message: "请输入编号", trigger: "blur" },
    ],
    zhCn: [
        { required: true, message: "请输入中文简体", trigger: "blur" },
    ]
})

const updateVisible = (val) => {
    emit('updatetable')
}

const getInit = async () => {
    let res = await Api.lang.add.post();
    if (res.code == 200) {
        kindOptions.value = res.configData.dictKindList
    }

}
const getData = async () => {
    // let params = {
    //     id: updataDialogId.value
    // }
    // paramsData:{ id: ''}
    console.log(props.paramsData)
    let res = await Api.lang.detail.post(props.paramsData);
    form.value = res.data
}
const updateLang = async (formRef) => {
    await formRef.validate((valid, fields) => {
        if (valid) {
            updateLangData();
        }
    })
}

const updateLangData = async () => {
    var params = {
        bean: form.value,
    }
    var res = await Api.lang.update.post(params);
    if (res.code == 200) {
        ElNotification.success({ title: '', message: '修改成功！', duration: 2000 });
        emit('updatetable', true)
    }
}


</script>

<style lang="less" scoped></style>

